<?php

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::redirect('/index.html', '/article', 301);
Route::get('/', 'PagesController@index')->name('root');
Route::get('/goto/{name}', 'PagesController@goTos')->name('goto');
Route::get('/top', 'TopController@index')->name('top');
Route::get('/site', 'SiteController@index')->name('site.index');
Route::paginate('/search/{action}/{name}', 'SearchController@index')->name('search');
Route::paginate('/site/{id}', 'SiteController@listId')->name('site.listId');
Route::paginate('/site/{son}/son/{id}', 'SiteController@listSonId')->name('site.listId');
Route::get('/siteinfo-{id}.html', 'SiteController@show')->name('site.show');

Route::get('sitemap', function(){
    // tags
    $sitemap_tags = App::make("sitemap");
    $tags     = DB::table('tags')->orderBy('created_at', 'desc')->get();
    foreach ($tags as $v)
    {
        $sitemap_tags->add(URL::to('/tags')."/$v->name", $v->created_at, '1.0', 'daily');
    }
    $sitemap_tags->store('xml','tags');

    $sitemap_articles = App::make("sitemap");
    $articles = DB::table('articles')->where(['state'=>1])->orderBy('created_at', 'desc')->get();
    foreach ($articles as $v)
    {
        $sitemap_articles->add(URL::to('/')."/artinfo-$v->id.html", $v->created_at, '1.0', 'daily');
    }
    $sitemap_articles->store('xml', 'articles');

    $sitemap_sites = App::make("sitemap");
    $sites = DB::table('sites')->where(['state'=>1])->orderBy('created_at', 'desc')->get();
    foreach ($sites as $v)
    {
        $sitemap_sites->add(URL::to('/')."/siteinfo-$v->id.html", $v->created_at, '1.0', 'daily');
    }
    $sitemap_sites->store('xml', 'sites');

    $sitemap_areas = App::make("sitemap");
    $areas = DB::table('areas')->orderBy('created_at', 'desc')->get();
    foreach ($areas as $v)
    {
        $sitemap_areas->add(URL::to('/')."/area/$v->name", $v->created_at, '1.0', 'daily');
    }
    $sitemap_areas->store('xml', 'areas');

    $sitemap = App::make ("sitemap");

    // add sitemaps (loc, lastmod (optional))
    $sitemap->addSitemap(URL::to('tags.xml'));
    $sitemap->addSitemap(URL::to('articles.xml'));
    $sitemap->addSitemap(URL::to('sites.xml'));
    $sitemap->addSitemap(URL::to('areas.xml'));

    // create file sitemap.xml in your public folder (format, filename)
    $sitemap->store('sitemapindex','sitemap');

});
Route::paginate('/area/{id}', 'SiteController@area')->name('site.area');
Route::paginate('/tags/{name}', 'SiteController@tag')->name('site.tag');

Route::get('/article', 'ArticleController@index')->name('article.index');
Route::paginate('/article/{id}', 'ArticleController@listId')->name('article.listId');
Route::get('/artinfo-{id}.html', 'ArticleController@show')->name('article.show');

Route::get('/pages/{name}.html', 'PagesController@pages')->name('pages');
Route::get('/icp/{id}', 'ApiController@icp')->name('icp');
Route::get('/seo/{id}', 'ApiController@seo')->name('seo');
Route::post('/rank', 'ApiController@rank')->name('rank');
Route::get('/snapshot/{id}', 'ApiController@snapshot')->name('snapshot');
Route::get('/shot/{url}', 'ApiController@webSiteShot')->name('shot');

Route::redirect('/diypage-1.html', '/pages/1.html', 301);
Route::redirect('/diypage-2.html', '/pages/2.html', 301);
Route::redirect('/diypage-3.html', '/pages/3.html', 301);
Route::redirect('/diypage-4.html', '/pages/4.html', 301);
Route::redirect('/diypage-5.html', '/pages/5.html', 301);
Route::redirect('/diypage-6.html', 'https://site.webshowu.com/diypage-6.html', 301);

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');
Route::get('/setting/security', 'HomeController@security')->name('setting.security');
Route::post('/setting/security', 'HomeController@securityUpdate')->name('setting.security.update');

Route::group(['middleware' => 'auth'], function() {
    Route::get('/email_verify_notice', 'EmailVerificationController@emailVerifyNotice')->name('email_verify_notice');
    Route::get('/email_verification/verify', 'EmailVerificationController@verify')->name('email_verification.verify');
    Route::get('/email_verification/send', 'EmailVerificationController@send')->name('email_verification.send');
    // 开始
    Route::group(['middleware' => 'email_verified'], function() {
        Route::get('website/claim', 'WebSiteController@claimGet');
        Route::get('website/claimDown', 'WebSiteController@claimDown');
        Route::post('website/claim/{action}', 'WebSiteController@claimPost');
        Route::post('website/classify', 'WebSiteController@classify')->name('website.classify');
        Route::post('website/img', 'WebSiteController@img')->name('website.img');
        Route::resource('website', 'WebSiteController');
    });
    // 结束
});